package com.nineclock.system.emp;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.system.pojo.SysCompanyUser;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class EmpParseListener extends AnalysisEventListener<Emp> {

    @Autowired
    private SysCompanyUserService sysCompanyUserService;

    private List<Emp> empList = new ArrayList<Emp>();
    public EmpParseListener(SysCompanyUserService syscompanyUserService) {
        this.sysCompanyUserService = syscompanyUserService;
    }
    //该方法每解析一行数据, 就会触发一次
    public void invoke(Emp data, AnalysisContext context) {
        System.out.println("-----> 解析到一行数据");
        empList.add(data);
    }

    //该方法是等所有行解析完毕之后触发
    public void doAfterAllAnalysed(AnalysisContext context) {
        //使用service调用
        sysCompanyUserService.saveUser(empList);
    }

}